<!doctype html>
<html lang="en-US">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Wechat.js</title>
  <link rel="stylesheet" href="http://typo.sofi.sh/typo.css"/>
  <style>
    body{padding:20px;}
    pre{margin:0 -20px;padding:30px 20px;font-size:14px;border:none;line-height:1;}
    code{color:#1a3;border:1px dashed #1a3;padding:1px 3px;}
    .reval{float:right;}
  </style>
</head>
<body class="typo">
<h1>Wechat.js</h1>

<p>
  当前使用的网络是：<code id="network">...</code>。
  用微信扫一扫下面的 url，然后分享到朋友圈:
</p>

<p><button onclick="toggle()">隐藏/显示分享按钮</button></p>
<p><button onclick="closeWebView()">关闭webview</button></p>
<p><button onclick="scanQRCode()">跳转到扫描二维码界面</button></p>
<p><button onclick="imagePreview()">图片预览/查看大图</button></p>
<p><button onclick="sendEmail()">分享到邮件</button></p>

<p><img src="http://ww4.sinaimg.cn/large/61b90cbegw1eknqctwzbhj2097097jrx.jpg" alt="sofish/wechat.js"/></p>

<p>详细使用指南请看：<a href="http://github.com/sofish/wechat.js/#readme">说明文档</a>。</p>

<script src="wechat.js"></script>
<script>
// 导入的数据
var data = {
  app: '',
  img: function() {
    return 'http://appled.cc/candy-theme-flat/images/share.jpg'
  },
  link: 'http://sofish.github.io/wechat.js/',
  desc: '用于处理微信分享的等小功能的 js 库',
  title: 'wechat.js'
};

var callback = function(res) {
  alert(JSON.stringify(res));
};

// 查看用户当前网络
// TODO: 这返回的数据好恶心
wechat('network', function(res) {
  document.getElementById('network').innerHTML = (res.err_msg.split(':')[1]);
});

// 分享
wechat('friend', data, callback);     // 朋友
wechat('timeline', data, callback);   // 朋友圈
wechat('weibo', data, callback);      // 微博

//控制右上角菜单是否显示,防止敏感信息泄露
var show = true;
function toggle(){
  var action = show ? 'hideOptionMenu' : 'showOptionMenu';
  wechat(action);
  show = !show;
}

// 关闭webview
function closeWebView() {
  wechat('closeWebView');
}

// 跳转到扫描二维码页面
function scanQRCode() {
  wechat('scanQRCode');
}

// 图片预览/查看大图
function imagePreview() {
  // 图片地址，恩，这部分漫画还有点意思
  var imageUrls = [
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914201786.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914202624.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914203364.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914204097.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914204740.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914205649.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914211050.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914211871.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914212444.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914213091.jpg",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914213952.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914214777.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914215454.gif",
    "http://pic003.cnblogs.com/2010/66372/201010/2010100914220482.gif",
    "http://pic003.cnblogs.com/2012/66372/201208/2012082923435810.gif",
    "http://pic003.cnblogs.com/2012/66372/201208/2012082923440536.gif",
    "http://pic003.cnblogs.com/2012/66372/201208/2012082923441776.gif"
  ];

  var imgData = {
    current: imageUrls[0],
    urls: imageUrls
  };

  wechat('imagePreview', imgData, callback);
}

// 发送邮件
function sendEmail() {
  wechat('email', data, callback);
}


</script>

</body>
</html>
